home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / uobj.com / UOBJ.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-01-10  |  2.8 KB  |  95 lines

  1. unit UObj;              {Turbo Pascal Version}              {90/01/08}
  2. {
  3.    This unit contains the TObj class and was written to:
  4.  
  5.      1) provide a "better" base object for Turbo Pascal programmers
  6.      2) enhance portability between Object Pascal and Turbo Pascal (MS/DOS)
  7.      3) provide the standard base object to Quick Pascal programmers
  8.  
  9.    Author: Mike Babulic                   Compuserve: 72307,314
  10.            3827 Charleswood Dr. N.W.
  11.            Calgary, Alberta
  12.            Canada
  13.            T2L 2C7
  14. }
  15. interface
  16.  
  17.   uses Objects;
  18.  
  19.   type
  20.     pTObj = ^TObj;
  21.     TObj = object(Base)
  22.       constructor Bind;
  23.                       {"Default" constructor;
  24.                           simply performs run-time binding.
  25.                             "New(v,Bind)" in Turbo
  26.                           is equivalent to:
  27.                             "New(v)" in Object Pascal (& Quick Pascal)}
  28.       function    Clone: Pointer;           virtual;
  29.                       {Copies SELF and returns a pointer to the copy
  30.                          Can override to copy objects referred to by
  31.                          fields of SELF}
  32.       procedure   Free;                     virtual;
  33.                       {Frees SELF from the heap.
  34.                          Can override to free objects referred to by
  35.                          fields of SELF}
  36.       function    ShallowClone: Pointer;    virtual;
  37.                       {Low-level copy; should not be overridden
  38.                          except in very unusual cases}
  39.       procedure   ShallowFree;              virtual;
  40.                       {Low-level method for freeing an object.
  41.                          Should not be overridden
  42.                          except in very unusual cases}
  43.       function    Bytes:Longint;            virtual;
  44.                       {Returns the number of bytes in SELF}
  45.       function    TypeOf:Pointer;           virtual;
  46.                       {Returns TypeOf(SELF)}
  47.       end;
  48.  
  49.     pTObject = ^TObj; {For compatability with Object Pascal programs}
  50.     TObject = TObj;
  51.  
  52. implementation
  53.  
  54.     constructor TObj.Bind;
  55.       begin
  56.       end;
  57.  
  58.     function TObj.ShallowClone: Pointer;
  59.       var t:pTObj;
  60.       begin
  61.         GetMem(t,SELF.Bytes);
  62.         Move(self,t^,SELF.Bytes);
  63.         ShallowClone := t;
  64.       end;
  65.  
  66.     procedure TObj.ShallowFree;
  67.       var t:pTObj;
  68.       begin
  69.         t := @self;
  70.         FreeMem(t,SELF.Bytes);
  71.       end;
  72.  
  73.     function TObj.Clone: Pointer;
  74.       begin
  75.         Clone := SELF.ShallowClone;
  76.       end;
  77.  
  78.     procedure TObj.Free;
  79.       begin
  80.         SELF.Done;
  81.         SELF.ShallowFree;
  82.       end;
  83.  
  84.     function TObj.Bytes:Longint;
  85.       begin
  86.         Bytes := SizeOf(SELF);
  87.       end;
  88.  
  89.     function TObj.TypeOf:Pointer;
  90.       begin
  91.         TypeOf := System.TypeOf(SELF);
  92.       end;
  93.  
  94.   end.
  95.